package com.wjqy.service.impl;

import com.wjqy.entity.*;
import com.wjqy.mapper.AdminMapper;
import com.wjqy.service.AdminService;
import com.wjqy.utils.RedeemCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    public List<Scenic> findAllScenic() {
        List<Scenic> allScenic = adminMapper.findAllScenic();
        return allScenic;
    }

    public List<Scenic> findScenicLike(Scenic scenic) {
        return adminMapper.findScenicLike(scenic);
    }

    public int countScenic() {
        return adminMapper.countScenic();
    }

    public int insertScenic(Scenic scenic) {
        int i = adminMapper.insertScenic(scenic);
        return i;
    }

    public int deleteScenic(int id) {
        int i = adminMapper.deleteScenic(id);
        return i;
    }

    public int updateScenic(Scenic scenic) {
        int i = adminMapper.updateScenic(scenic);
        return i;
    }

    public List<Active> findAllActivies(int id) {
        List<Active> allActivies = adminMapper.findAllActivies(id);
        return allActivies;
    }

    public int insertActive(Active active) {
        int i = adminMapper.insertActive(active);
        return i;
    }

    public int deleteActive(int id) {
        int i = adminMapper.deleteActive(id);
        return i;
    }

    public int updateActive(Active active) {
        int i = adminMapper.updateActive(active);
        return i;
    }

    public List<Recommend> findAllRcmd(int id) {
        List<Recommend> allRcmd = adminMapper.findAllRcmd(id);
        return allRcmd;
    }

    public int insertRecommend(Recommend rcmd) {
        int i = adminMapper.insertRecommend(rcmd);
        return i;
    }

    public int deleteRecommend(int id) {
        int i = adminMapper.deleteRecommend(id);
        return i;
    }

    public int updateRecommend(Recommend rcmd) {
        int i = adminMapper.updateRecommend(rcmd);
        return i;
    }

    public int createCdkey(int num, int scenicId) {
        List<Cdkey> cdklist = new ArrayList<Cdkey>();
        Date time = new Date();
        for (int i = 0; i < num; i++) {
            cdklist.add(new Cdkey(scenicId,RedeemCodeUtils.createBigStrOrNumberRadom(16),time));
        }
        return adminMapper.createCDK(cdklist);
    }

    public boolean changeUserStatus(User user) {
        if (user.getLevel()==2){
            String code = UUID.randomUUID().toString().replace("-", "");
            user.setCode(code);
        }
        int i = adminMapper.changeUserStatus(user);
        return i>0;
    }

    public List<User> listVerifyUser() {
        List<User> users = adminMapper.listVerifyUser();
        return users;
    }

    public boolean setTopLevel(User user) {
        String code = UUID.randomUUID().toString().replace("-", "");
        user.setCode(code);
        int i = adminMapper.setTopLevel(user);
        return i>0;
    }
}
